home *** CD-ROM | disk | FTP | other *** search
/ Windows Expert / Windows Expert.iso / utility / 5in1.zip / 5IN1.C next >
C/C++ Source or Header  |  1991-04-07  |  10KB  |  379 lines

  1. /*
  2.                Five in one
  3.  
  4.                (c) Eric Lapaille - Belgium - 1991
  5.  
  6.                Do not remove this comment
  7.  
  8. */
  9.  
  10. #include "no.h"
  11. #include <windows.h>
  12. #include <string.h>
  13. #include <stdlib.h>
  14. #include <stdio.h>
  15. #include <dos.h>
  16.  
  17. #if (_MSC_VER >= 600)
  18.    long FAR PASCAL WndProc( HWND , unsigned ,WORD , LONG );
  19. #else
  20.    /* Borland C++ (don't know for Zortech and Topspeed) */
  21.    long FAR PASCAL _export WndProc( HWND , unsigned ,WORD , LONG );
  22. #endif
  23.  
  24. BOOL FAR PASCAL About        (HWND , unsigned , WORD , LONG );
  25. BOOL FAR PASCAL ShellWnd     (HWND , unsigned , WORD , LONG );
  26.  
  27. void emm_get_num_pages( int *, int *);
  28. void SetFontScreen (void);
  29. void Process(short);
  30.  
  31. #define EMS 1
  32. #define IDM_ABOUT  100
  33. #define IDM_FAST   101
  34. #define IDM_SHELL  102
  35.  
  36. #define IDSH      200
  37.  
  38. BOOL    bBlack     = FALSE;
  39. BOOL    bFirstShell=FALSE;
  40. BOOL    bMode      = FALSE;
  41. FARPROC lpProcShell;
  42. HANDLE  hInst;
  43. HWND    hWShell,hOldWnd;
  44. HWND    hWnd;
  45. LOGFONT logfont;
  46. char    szAppName[]  = "5IN1";
  47.  
  48. /* ---------------------------------------------------------- */
  49.  
  50. int PASCAL WinMain( HANDLE hInstance, HANDLE hPrevInstance, LPSTR lpszCmdLine, int cmdShow )
  51.   {
  52.   WNDCLASS WndClass;
  53.   MSG      msg;
  54.  
  55.   DWORD    dwFlags;
  56.   HMENU    hMenu;
  57.  
  58.   if (hPrevInstance)
  59.      return FALSE;
  60.  
  61.   WndClass.hCursor          = LoadCursor( NULL, IDC_ARROW );
  62.   WndClass.hIcon            = NULL;
  63.   WndClass.cbClsExtra        = 0;
  64.   WndClass.cbWndExtra        = 0;
  65.   WndClass.lpszMenuName        = szAppName;
  66.   WndClass.lpszClassName    = szAppName;
  67.   WndClass.hbrBackground    = (HBRUSH)GetStockObject( LTGRAY_BRUSH );
  68.   WndClass.hInstance        = hInstance;
  69.   WndClass.style            = CS_HREDRAW | CS_VREDRAW;
  70. #if (_MSC_VER >= 600)
  71.    #pragma message ("sorry, no way to suppress specific warning with Microsoft")
  72.    cmdShow = cmdShow;
  73. #else
  74.    #pragma warn -sus
  75. #endif
  76.   WndClass.lpfnWndProc      = WndProc;
  77.  
  78.   if (!RegisterClass( (LPWNDCLASS)&WndClass ) )
  79.      return(FALSE);
  80.  
  81.   SetFontScreen();
  82.  
  83.   bFirstShell = (GetNumTasks() == 1);
  84.  
  85.   hWnd = CreateWindow(szAppName, szAppName,
  86.               WS_OVERLAPPED | WS_CAPTION| WS_SYSMENU ,
  87.               0, 0, 40, 40, NULL, NULL, hInstance, NULL );
  88.  
  89.   if (!SetTimer( hWnd, 1, 2000, NULL ))
  90.      return FALSE;
  91.  
  92.   hInst = hInstance;
  93.  
  94.   dwFlags = GetWinFlags();
  95.  
  96.   if (dwFlags & WF_ENHANCED)
  97.      SetWindowText(hWnd," Enhanced Mode ");
  98.   else
  99.      {
  100.      if (dwFlags & WF_STANDARD)
  101.         SetWindowText(hWnd, " Standard Mode ");
  102.      else
  103.         SetWindowText(hWnd, " Real Mode ");
  104.      }
  105.   if (dwFlags & WF_SMALLFRAME || dwFlags & WF_LARGEFRAME)
  106.      bMode = EMS;
  107.  
  108.   hMenu = GetSystemMenu(hWnd,FALSE);
  109.   AppendMenu(hMenu, MF_SEPARATOR, NULL      ,(LPSTR)NULL          );
  110.   AppendMenu(hMenu, MF_STRING   , IDM_ABOUT ,(LPSTR)"&About ..."  );
  111.   AppendMenu(hMenu, MF_STRING   , IDM_FAST  ,(LPSTR)"Fast &Exit"  );
  112.   AppendMenu(hMenu, MF_STRING   , IDM_SHELL ,(LPSTR)"Small S&hell");
  113.  
  114.   ShowWindow( hWnd, SW_SHOWMINIMIZED );
  115.   UpdateWindow( hWnd );
  116.   if (bFirstShell)
  117.      {
  118.      char szB[80];
  119.  
  120.      if (lpszCmdLine[0])
  121.         Process(WinExec(lpszCmdLine,SW_SHOW));
  122.      GetProfileString ("windows","load","",szB,80);
  123.      if (szB[0])
  124.         Process(WinExec(szB,SW_SHOWMINIMIZED));
  125.      GetProfileString ("windows","run" ,"",szB,80);
  126.      if (szB[0])
  127.         Process(WinExec(szB,SW_SHOW));
  128.      }
  129.  
  130.   while (GetMessage( &msg, NULL, 0, 0 ))
  131.      {
  132.      if (!(hWShell && IsDialogMessage(hWShell,&msg)))
  133.         {
  134.         TranslateMessage( &msg );
  135.         DispatchMessage( &msg );
  136.         }
  137.      }
  138.  
  139.   return (int)msg.wParam;
  140.   }
  141.  
  142. // ----------------------------------------------------------
  143. #if (_MSC_VER >= 600)
  144.    long FAR PASCAL WndProc( HWND hWnd, unsigned message,WORD wParam, LONG lParam )
  145. #else
  146.    long FAR PASCAL _export WndProc( HWND hWnd, unsigned message,WORD wParam, LONG lParam )
  147. #endif
  148. {
  149.   static int mem2,mem1,lastmem1,lastmem2;
  150.   char buffer[20];
  151.   PAINTSTRUCT ps;
  152.   FARPROC lpProc;
  153.   RECT rect;
  154.   int num_pages, unalloc_pages;
  155.   HFONT hFont;
  156.  
  157.   switch (message)
  158.      {
  159.      case WM_COMPACTING:
  160.         {
  161.         short nI;
  162.         for (nI = 0 ; nI<5 ; nI++)
  163.            FlashWindow(hWnd, 0);
  164.         }
  165.         break;
  166.  
  167.      case WM_TIMER:
  168.         switch (wParam)
  169.            {
  170.            case 1:
  171.               mem1 = (int) ( GetFreeSpace (0) / 1024L);
  172.               if (bMode == EMS)
  173.                  {
  174.                  emm_get_num_pages( &num_pages, &unalloc_pages );
  175.                  mem2 = unalloc_pages * 16;
  176.                  }
  177.               if (mem1 != lastmem1 || mem2 !=lastmem2)
  178.                  InvalidateRect( hWnd, NULL, TRUE );
  179.               lastmem1 = mem1;
  180.               lastmem2 = mem2;
  181.               break;
  182.            }
  183.         break;
  184.  
  185.      case WM_PAINT:
  186.         
  187.         BeginPaint( hWnd, (LPPAINTSTRUCT)&ps );
  188.         strcat( itoa( mem1, buffer, 10 ), "K" );
  189.         hFont = SelectObject (ps.hdc, CreateFontIndirect(&logfont));
  190.         GetClientRect(hWnd,(LPRECT)&rect);
  191.         MoveTo(ps.hdc,0,rect.bottom-1);
  192.         SelectObject(ps.hdc,GetStockObject(WHITE_PEN));
  193.         LineTo(ps.hdc,0,rect.top);
  194.         LineTo(ps.hdc,rect.right-1,rect.top);
  195.         SelectObject(ps.hdc,GetStockObject(BLACK_PEN));
  196.         LineTo(ps.hdc,rect.right-1,rect.bottom-1);
  197.         LineTo(ps.hdc,0,rect.bottom-1);
  198.         SetBkMode(ps.hdc,TRANSPARENT);
  199.         SetTextColor(ps.hdc,RGB(0,0,255));
  200.         TextOut( ps.hdc, 1,  1, buffer, strlen( buffer ) );
  201.         if (bMode == EMS)
  202.            {
  203.            strcat( itoa( mem2, buffer, 10 ), "K" );
  204.            SetTextColor(ps.hdc,RGB(0,255,0));
  205.            TextOut( ps.hdc, 0, 11, buffer, strlen( buffer ) );
  206.            }
  207.         strcat( itoa( GetNumTasks(), buffer, 10 ), " T" );
  208.         SetTextColor(ps.hdc,RGB(255,0,0));
  209.         TextOut( ps.hdc, 1, 21, buffer, strlen( buffer ) );
  210.         DeleteObject (SelectObject (ps.hdc, hFont));
  211.         EndPaint( hWnd, (LPPAINTSTRUCT)&ps );
  212.         break;
  213.  
  214.      case WM_SYSCOMMAND:
  215.         switch (wParam)
  216.            {
  217.            case IDM_ABOUT:
  218.               lpProc = MakeProcInstance(About, hInst);
  219.               DialogBox(hInst,"AboutBox",hWnd,lpProc);
  220.               FreeProcInstance(lpProc);
  221.               break;
  222.            case IDM_FAST:
  223.               ExitWindows(0,0);
  224.               break;
  225.            case IDM_SHELL:
  226.               if (hWShell)
  227.                  {
  228.                  SetFocus(GetDlgItem(hWShell,IDSH));
  229.                  SendDlgItemMessage(hWShell,IDSH,EM_SETSEL,0,MAKELONG(0,32767));
  230.                  }
  231.               else
  232.                  {
  233.                  lpProcShell = MakeProcInstance(ShellWnd, hInst);
  234.                  hWShell = CreateDialog(hInst,"SHELL",hWnd,lpProcShell);
  235.                  }
  236.               break;
  237.        default:
  238.               break;
  239.        }
  240.     return DefWindowProc( hWnd, message, wParam, lParam );
  241.  
  242.     case WM_DESTROY:
  243.        KillTimer( hWnd, 1 );
  244.        PostQuitMessage( 0 );
  245.        break;
  246.  
  247.     case WM_CLOSE:
  248.        if (bFirstShell)
  249.           {
  250.           if (!ExitWindows(0,0))
  251.              break;
  252.           }
  253.        // no break;
  254.     default:
  255.        return DefWindowProc( hWnd, message, wParam, lParam );
  256.     }
  257.     return(0L);
  258. }
  259.  
  260.  
  261. // ----------------------------------------------------------
  262.  
  263. BOOL FAR PASCAL About(HWND hDlg, unsigned message, WORD wParam, LONG lParam)
  264. {
  265.     lParam=lParam;
  266.     switch (message)
  267.        {
  268.        case WM_INITDIALOG:
  269.           return (TRUE);
  270.  
  271.        case WM_COMMAND:
  272.       if (wParam == IDOK || wParam == IDCANCEL)
  273.              {
  274.          EndDialog(hDlg, TRUE);
  275.          return (TRUE);
  276.              }
  277.           break;
  278.        }
  279.     return (FALSE);
  280. }
  281.  
  282. // ----------------------------------------------------------
  283.  
  284. void SetFontScreen ()
  285.    {
  286.    logfont.lfHeight         = 1;
  287.    logfont.lfWidth          = 1;
  288.    logfont.lfEscapement     = 0;
  289.    logfont.lfOrientation    = 0;
  290.    logfont.lfWeight         = 400;
  291.    logfont.lfItalic         = 0;
  292.    logfont.lfUnderline      = 0;
  293.    logfont.lfStrikeOut      = 0;
  294.    logfont.lfCharSet        = ANSI_CHARSET ;
  295.    logfont.lfOutPrecision   = OUT_DEFAULT_PRECIS;
  296.    logfont.lfClipPrecision  = CLIP_DEFAULT_PRECIS;
  297.    logfont.lfQuality        = DEFAULT_QUALITY;
  298.    logfont.lfPitchAndFamily = VARIABLE_PITCH | FF_ROMAN ;
  299.    strcpy (logfont.lfFaceName, "Tms Rmn") ;
  300.    }
  301.  
  302. // ----------------------------------------------------------
  303.  
  304. BOOL FAR PASCAL ShellWnd(HWND hDlg, unsigned message, WORD wParam, LONG lParam)
  305.    {
  306.    short nRet;
  307.    char szBuf[60];
  308.  
  309.    #if (_MSC_VER >= 600)
  310.       lParam=lParam;
  311.    #else
  312.       #pragma warn -par
  313.    #endif
  314.  
  315.    switch (message)
  316.       {
  317.       case WM_INITDIALOG:
  318.          ShowWindow(hDlg,SW_SHOW);
  319.          return TRUE;
  320.  
  321.       case WM_COMMAND:
  322.          switch (wParam)
  323.             {
  324.             case IDOK:
  325.                GetDlgItemText(hDlg,IDSH,szBuf,60);
  326.                if (szBuf[0])
  327.                   {
  328.                   nRet=WinExec(szBuf,SW_SHOW);
  329.                   Process(nRet);
  330.                   if (nRet <32)
  331.                      {
  332.                      SetFocus(GetDlgItem(hDlg,IDSH));
  333.                      SendDlgItemMessage(hDlg,IDSH,EM_SETSEL,0,MAKELONG(0,32767));
  334.                      }
  335.                   }
  336.                else
  337.                   MessageBeep(MB_OK);
  338.                break;
  339.             default:
  340.                break;
  341.             }
  342.          break;
  343.       case WM_CLOSE:
  344.          DestroyWindow(hDlg);
  345.          hWShell=0;
  346.          FreeProcInstance(lpProcShell);
  347.          return TRUE;
  348.       default:
  349.          break;
  350.       }
  351.    return FALSE;
  352.    }
  353.  
  354. // ----------------------------------------------------------
  355.  
  356. void emm_get_num_pages( int *num_pages, int *unalloc_pages )
  357.   {
  358.   union REGS regs;
  359.  
  360.   regs.h.ah = 0x42;
  361.   int86( 0x67, ®s, ®s );
  362.   *num_pages = regs.x.dx;
  363.   *unalloc_pages = regs.x.bx;
  364.   }
  365.  
  366.  
  367. void Process(short nRet)
  368.    {
  369.    if (nRet < 32)
  370.       {
  371.       char szBuf[60];
  372.  
  373.       MessageBeep(MB_OK);
  374.       if (!LoadString(hInst,nRet,szBuf,60))
  375.          sprintf(szBuf,"Undocumented Error %d",nRet);
  376.       MessageBox(hWnd, szBuf,"Error",MB_OK|MB_TASKMODAL|MB_ICONSTOP);
  377.       }
  378.    }
  379.